package vn.bk.legends.alarmtraffic;

import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import vn.bk.legends.alarmtrafic.R;
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends FragmentActivity {

    private GoogleMap gMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	try {
	    MapsInitializer.initialize(this);
	} catch (GooglePlayServicesNotAvailableException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
	gMap = ((SupportMapFragment) getSupportFragmentManager()
		.findFragmentById(R.id.map)).getMap();
	gMap.addMarker(new MarkerOptions()
	    .position(new LatLng(SplashScreen.latitude, SplashScreen.longtitude)).title("My Location")
	    .icon(BitmapDescriptorFactory.fromResource(R.drawable.me)));
	
	gMap.setOnMapLongClickListener(new OnMapLongClickListener() {
	    
	    @Override
	    public void onMapLongClick(LatLng point) {
		// TODO Auto-generated method stub
		showSettingAlarm(point);
	    }
	});
	
    }
    
    private void showSettingAlarm(LatLng target){
	float[] results = new float[]{};
	Location.distanceBetween(SplashScreen.latitude, SplashScreen.longtitude, target.latitude, target.longitude, results);
	if(results[0] < 1000){
	    Toast.makeText(this, "alarm", Toast.LENGTH_SHORT).show();
	}
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);
	return true;
    }

}
